﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class FriendSearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {

        }
        else
        {
            Friend.WebDirectory = Server.MapPath("App_Data");
            Friend friend = new Friend("first", "last", "muser", "museremail");
            LoadPossibleFriendList(friend);
        }
    }

    protected void LoadPossibleFriendList(Friend friend)
    {
        if (friend.hasFriendListFile())
        {
            friend.FriendList = friend.GetFriendListFromFile();

            foreach (Friend aFriend in friend.FriendList)
            {
                if (aFriend.hasFriendListFile())
                {
                    aFriend.FriendList = aFriend.GetFriendListFromFile();
                    foreach (Friend friendFriend in aFriend.FriendList)
                    {
                        lbxFriends.Items.Add(friendFriend.ToString());

                    }
                }
            }
        }

    }

    protected void btnAddFriend_Click(object sender, EventArgs e)
    {
        String item = lbxFriends.SelectedValue;
        Friend friend = new Friend("first", "last", "muser", "museremail");

        if (friend.hasFriendListFile())
        {
            Friend newFriend = friend.SplitFriendTextToObject(item);
            friend.AddFriendEntryToFile(newFriend);
        }
    }
    protected void lbxFriends_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}